package com.truth.lock.key;

import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.stream.Collectors;

/**
 * 默认的Key生成策略
 * @author truth
 */
public class DefaultKeyGenerator implements KeyGenerator{

    @Override
    public Object generate(Object target, Method method, Object... params) {
        String className = target.getClass().getName();
        String methodName = method.getName();
        String paramsString = Arrays.stream(params).map(String::valueOf).collect(Collectors.joining("-"));
        return String.join(":", Arrays.asList(className, methodName, paramsString));
    }
}
